# coding: utf-8
# flask自动产生orm的工具产生
from application import db,app

class Member(db.Model):
    __tablename__ = 'member'

    id = db.Column(db.Integer, primary_key=True)
    nickname = db.Column(db.String(100), nullable=False, server_default=db.FetchedValue(), info='???')
    mobile = db.Column(db.String(11), nullable=False, server_default=db.FetchedValue(), info='??????')
    sex = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue(), info='?? 1?? 2??')
    avatar = db.Column(db.String(200), nullable=False, server_default=db.FetchedValue(), info='????')
    salt = db.Column(db.String(32), nullable=False, server_default=db.FetchedValue(), info='??salt')
    reg_ip = db.Column(db.String(100), nullable=False, server_default=db.FetchedValue(), info='??ip')
    status = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue(), info='?? 1??? 0???')
    updated_time = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue(), info='????????')
    created_time = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue(), info='????')

# 添加虚拟属性 装饰器是property 这样就能把数据库中对应的数字  用文字来表述
    @property
    def status_desc(self):
        # 通过从base_setting 的状态值STATUS_MAPPING里面取得当前的status转换成字符串
        return app.config['STATUS_MAPPING'][str(self.status)]

    @property
    def sex_desc(self):
        # 定义一个数组sex_mapping
        sex_mapping ={
            "0":"女",
            "1":"男"
            # "2":"女"
        }
        # 通过sex_mapping字典中获得当前sex的表述字段
        return sex_mapping[str(self.sex)]
